package com.example.hello;

import com.example.hello.client.Modal.BootstrapModalState;
import com.vaadin.shared.Connector;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Component;

import java.util.LinkedList;
import java.util.List;

public class BootstrapModal extends AbstractComponent {

    public enum BackdropType {
        NONE, NORMAL, STATIC
    }

    public BootstrapModal() {
        setAnimation(true);
        setCloseVisible(true);
        setDynamicSafe(true);
        setKeyboard(true);
    }

    public List<Component> getWidgets() {
        List<Component> widgets = new LinkedList<>();
        for (Connector connector : getState().getWidgets()) {
            widgets.add((Component) connector);
        }

        return widgets;
    }

    public void setWidgets(List<Component> widgets) {
        List<Connector> connectorList = new LinkedList<>();
        for (Component widget : widgets) {
            connectorList.add(widget);
        }

        getState().setWidgets(connectorList);
    }

    @Override
    protected BootstrapModalState getState() {
        return (BootstrapModalState) super.getState();
    }

    public void addWidget(Component widget) {
        getState().addWidget(widget);
    }

    public void addWidget(int index, Component widget) {
        getState().addWidget(widget, index);
    }

    public void removeWidget(Component widget) {
        getState().removeWidget(widget);
    }

    public boolean isAnimation() {
        return getState().isAnimation();
    }

    public void setAnimation(boolean animation) {
        getState().setAnimation(animation);
    }

    public BackdropType getBackdrop() {
        return BackdropType.valueOf(getState().getBackdrop());
    }

    public void setBackdrop(String backdrop) {
        getState().setBackdrop(backdrop);
    }

    public boolean isCloseVisible() {
        return getState().isCloseVisible();
    }

    public void setCloseVisible(boolean closeVisible) {
        getState().setCloseVisible(closeVisible);
    }

    public boolean isDynamicSafe() {
        return getState().isDynamicSafe();
    }

    public void setDynamicSafe(boolean dynamicSafe) {
        getState().setDynamicSafe(dynamicSafe);
    }

    public boolean isKeyboard() {
        return getState().isKeyboard();
    }

    public void setKeyboard(boolean keyboard) {
        getState().setKeyboard(keyboard);
    }

    public void show() {
        getState().setShowFlag(true);
    }

    public void hide() {
        getState().setShowFlag(false);
    }

}
